/**
 * 国家和地方科技计划项目
 */
enterprsie_project_store = Ext.extend(Ext.data.GroupingStore, {
	constructor : function() {
		// this.cfg = _cfg;
		enterprsie_project_store.superclass.constructor.call(this, {
			proxy : new Ext.data.HttpProxy({
				url : 'cxxqysjsb/enterprise_project/getallenterprsie_project.action?uid='
						+ userId,// 用户的ID
				method : 'post'
			}),
			autoLoad : true,
			sortInfo : {
				field : 'project_id',
				direction : "ASC"
			},
			groupField : 'project_year',
			reader : new Ext.data.JsonReader({
						fields : ['project_id', 'editable', 'enterprise_id',
								'project_type', 'project_is_major',
								'project_is_new', 'project_type_sb',
								'project_check_pass', 'project_name',
								'project_start_time', 'project_end_time',
								'project_year', 'project_government_money']
					})
		})
	}
});
enterprsie_project_info_grid = Ext.extend(Ext.grid.GridPanel, {
	store : null,
	addwin : null,
	editwin : null,
	constructor : function() {
		this.store = new enterprsie_project_store();
		this.addwin = new addenterprsie_project_formpanel_win();
		enterprsie_project_info_grid.superclass.constructor.call(this, {
			loadMask : {
				msg : '数据加载中...'
			},
			title : '企业基本情况-国家和地方科技计划项目情况',
			iconCls : 'SMLPoolManage_sml',
			sm : arrsm,
			frame : true,
			view : new Ext.grid.GroupingView({
				forceFit : true,
				groupTextTpl : '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "条数据" : "条数据"]})'
			}),
			cm : new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
						header : 'ID',
						width : 10,
						dataIndex : 'project_id',
						id : 'project_id',
						hidden : true,
						align : 'center'
					}, {
						header : '企业编号',
						width : 10,
						dataIndex : 'enterprise_id',
						id : 'enterprise_id',
						hidden : true,
						align : 'center'
					}, {
						header : '年度',
						width : 80,
						dataIndex : 'project_year',
						id : 'project_year',
						renderer : this.project_yearName,
						hidden : true,
						align : 'center'
					}, {
						header : '项目类型',
						width : 100,
						dataIndex : 'project_type',
						id : 'project_type',
						renderer : this.getproject_typename,
						sortable : false,
						align : 'center'
					}, {
						header : '第一承担单位',
						width : 100,
						dataIndex : 'project_is_major',
						id : 'project_is_major',
						sortable : false,
						renderer : this.getmajorname,
						align : 'center'
					}, {
						header : '项目名称',
						width : 100,
						dataIndex : 'project_name',
						id : 'project_name',
						sortable : false,
						align : 'center'
					}, {
						header : '启动日期',
						width : 100,
						dataIndex : 'project_start_time',
						id : 'project_start_time',
						sortable : false,
						align : 'center'
					}, {
						header : '结束日期',
						width : 100,
						dataIndex : 'project_end_time',
						id : 'project_end_time',
						sortable : false,
						align : 'center'
					}, {
						header : '政府经费',
						width : 100,
						dataIndex : 'project_government_money',
						id : 'project_government_money',
						sortable : false,
						renderer : this.getmoneyname,
						align : 'center'
					}, {
						header : '申报类型',
						width : 100,
						dataIndex : 'project_type_sb',
						id : 'project_type_sb',
						sortable : false,
						renderer : this.getproject_type_sbName,
						align : 'center'
					}, {
						header : '审核状态',
						width : 100,
						dataIndex : 'project_check_pass',
						id : 'project_check_pass',
						sortable : false,
						renderer : this.project_check_passName,
						align : 'center'
					}]),
			tbar : [{
				text : '增加<font color="red">' + OPTION_NDDECLARE_YEAR + '年'
						+ getDataType(OPTION_DATA_TYPE) + '</font>标准制定数据',
				scope : this,
				iconCls : 'itemadd',
				handler : function() {
					this.addwin.show(Ext.getDom('project_check_pass'));
				}
			}, '-', {
				text : '修改',
				scope : this,
				tooltip : '只允许修改草稿数据',
				iconCls : 'smlEdit_edit',
				handler : function() {
					var ro = this.getSelectionModel().getSelected();
					if (!ro) {
						Ext.Msg.show({
									title : '提示',
									msg : '没有选择数据',
									icon : Ext.Msg.ERROR,
									buttons : Ext.Msg.OK
								});
						return;
					}
					var project_check_pass = ro.get('project_check_pass');
					if (project_check_pass == 0) {
						Ext.Msg.show({
									title : '提示',
									msg : '正在审核的数据不能修改',
									icon : Ext.Msg.ERROR,
									buttons : Ext.Msg.OK
								});
						return;
					}
					if (project_check_pass == 1 || project_check_pass == 2) {
						Ext.Msg.show({
									title : '提示',
									msg : '审核完成的数据不能修改',
									icon : Ext.Msg.ERROR,
									buttons : Ext.Msg.OK
								});
						return;
					}
					var cfg = {
						pid : ro.get('project_id'),
						eid:ro.get('enterprise_id'),
						year : ro.get('project_year'),
						project_type : ro.get('project_type'),
						project_is_major : ro.get('project_is_major'),
						project_name : ro.get('project_name'),
						project_start_time : ro.get('project_start_time'),
						project_end_time : ro.get('project_end_time'),
						project_government_money : ro
								.get('project_government_money'),
						type : ro.get('project_type_sb')
					}
					this.editwin = new editenterprsie_project_formpanel_win(cfg);
					this.editwin.show(Ext.getDom('project_check_pass'));
					this.editwin.on('editok', function() {
								this.getStore().reload();
							}, this);
				}
			}, '-', {
				text : '刷新',
				scope : this,
				iconCls : 'refreshtty',
				handler : function() {
					this.getStore().reload();
				}
			}]
		});
		this.addwin.on('addok', function() {
					this.getStore().reload()
				}, this);
	},
	getproject_type_sbName : function(code) {
		return '<font color="red">' + getDataType(code) + '</font>';
	},
	project_check_passName : function(code) {
		return getCheckResultName(code);
	},
	getmoneyname : function(value) {
		return value + '万元';
	},
	getmajorname : function(code) {
		return getenterpriseprojectmajortype_combox_store(code);
	},
	getproject_typename : function(code) {
		return getstatelocaltype_combox_store(code);
	},
	project_yearName : function(code) {
		return code + '年';
	}
});
/**
 * 增加一条国家地方计划项目
 * 
 * @class addenterprsie_project_formpanel
 * @extends Ext.form.FormPanel
 */
addenterprsie_project_formpanel = Ext.extend(Ext.form.FormPanel, {
	constructor : function() {
		addenterprsie_project_formpanel.superclass.constructor.call(this, {
					frame : true,
					height : 220,
					bodyStyle : 'padding: 10px 0px 0 10px;',
					labelWidth : 80,
					labelAlign : 'right',
					defaults : {
						anchor : '95%',
						allowBlank : true,
						msgTarget : 'side'
					},
					items : [{
								xtype : 'hidden',
								name : 'userid',
								value : userId
							}, {
								xtype : 'textfield',
								fieldLabel : '申报年度',
								anchor : '99%',
								name : 'type',
								readOnly : true,
								disabled : true,
								value : OPTION_NDDECLARE_YEAR + '年'
										+ getDataType(OPTION_DATA_TYPE) + ''
							}, {
								xtype : 'combo',
								fieldLabel : '项目类型',
								hiddenName : 'project_type',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								store : statelocaltype_combox_store,
								emptyText : '请选择项目类型',
								allowBlank : false,
								blankText : '请选择项目类型'
							}, {
								xtype : 'combo',
								fieldLabel : '第一承担单位',
								hiddenName : 'project_is_major',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								store : enterpriseprojectmajortype_combox_store,
								emptyText : '请选择是否是第一承担单位',
								allowBlank : false,
								blankText : '请选择是否是第一承担单位'
							}, {
								xtype : 'textfield',
								fieldLabel : '项目名称',
								name : 'project_name',
								allowBlank : false,
								blankText : '项目名称不能为空',
								anchor : '99%'
							}, {
								xtype : 'datefield',
								fieldLabel : '启动时间',
								name : 'project_start_time',
								allowBlank : false,
								blankText : '启动时间不能为空',
								anchor : '99%'
							}, {
								xtype : 'datefield',
								fieldLabel : '结束时间',
								name : 'project_end_time',
								allowBlank : false,
								blankText : '结束时间不能为空',
								anchor : '99%'
							}, {
								xtype : 'textfield',
								fieldLabel : '政府拨付经费（万元）',
								name : 'project_government_money',
								allowBlank : false,
								regex : /^[0-9]+$/,
								blankText : '政府拨付经费不能为空',
								anchor : '99%'
							}]
				});
	}
});
addenterprsie_project_formpanel_win = Ext.extend(Ext.Window, {
	panel : null,
	constructor : function() {
		this.panel = new addenterprsie_project_formpanel();
		addenterprsie_project_formpanel_win.superclass.constructor.call(this, {
					width : 500,
					title : '申报<font color="red">' + OPTION_NDDECLARE_YEAR
							+ '年' + getDataType(OPTION_DATA_TYPE)
							+ '</font>标准制定数据',
					iconCls : 'itemadd',
					// layout : 'form',
					closeAction : 'hide',
					frame : true,
					modal : true,
					plain : true,
					items : this.panel,
					buttons : [{
								text : '保存草稿',
								scope : this,
								iconCls : 'itemadd',
								handler : this.submit
							}, {
								text : '取消',
								scope : this,
								iconCls : 'cancel',
								handler : function() {
									this.panel.getForm().reset();
									this.hide()
								}
							}]
				});
		this.addEvents('addok');
	},
	submit : function() {
		var form = this.panel.getForm();
		if (!form.isValid()) {
			Ext.Msg.show({
						title : '提示',
						msg : '请正确填写数据',
						icon : Ext.Msg.ERROR,
						buttons : Ext.Msg.OK
					});
			return;
		} else {
			var uid = form.findField('userid').getValue();
			var project_type = form.findField('project_type').getValue();
			var project_is_major = form.findField('project_is_major')
					.getValue();
			var project_name = form.findField('project_name').getValue();
			var project_start_time = form.findField('project_start_time')
					.getValue();
			var project_end_time = form.findField('project_end_time')
					.getValue();
			var project_government_money = form
					.findField('project_government_money').getValue();
			Ext.Ajax.request({
				url : 'cxxqysjsb/enterprise_project/insertnewenterprsie_project.action',
				params : {
					uid : uid,
					year : OPTION_NDDECLARE_YEAR,
					type : OPTION_DATA_TYPE,
					project_type : project_type,
					project_is_major : project_is_major,
					project_name : project_name,
					project_start_time : project_start_time,
					project_end_time : project_end_time,
					project_government_money : project_government_money
				},
				scope : this,
				success : function(response, options) {
					if (response.responseText == 'ok') {
						this.fireEvent('addok');
						this.hide();
					} else if (response.responseText == 'fail') {
						Ext.Msg.show({
									title : '提示',
									msg : '数据传输失败',
									icon : Ext.Msg.WARNING,
									buttons : Ext.Msg.OK
								});
						return;
					}
				}
			});
		}

	}
});
/**
 * 修改面板
 * 
 * @class editenterprsie_project_formpanel
 * @extends Ext.form.FormPanel
 */
editenterprsie_project_formpanel = Ext.extend(Ext.form.FormPanel, {
			cfg : null,
			constructor : function(_cfg) {
				this.cfg = _cfg;
				editenterprsie_project_formpanel.superclass.constructor.call(
						this, {
							frame : true,
							height : 190,
							bodyStyle : 'padding: 10px 0px 0 10px;',
							labelWidth : 80,
							labelAlign : 'right',
							defaults : {
								anchor : '95%',
								allowBlank : true,
								msgTarget : 'side'
							},
							items : [{
								xtype : 'hidden',
								name : 'pid',
								value : this.cfg.pid
									// 标准ID
								}, {
								xtype : 'hidden',
								name : 'eid',
								value : this.cfg.eid
									// 企业ID
								}, {
								xtype : 'combo',
								fieldLabel : '项目类型',
								hiddenName : 'project_type',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								value : this.cfg.project_type,
								store : statelocaltype_combox_store,
								emptyText : '请选择项目类型',
								allowBlank : false,
								blankText : '请选择项目类型'
							}, {
								xtype : 'combo',
								fieldLabel : '第一承担单位',
								hiddenName : 'project_is_major',
								triggerAction : 'all',
								displayField : 'name',
								readOnly : true,
								valueField : 'id',
								mode : 'local',
								anchor : '99%',
								value : this.cfg.project_is_major,
								store : enterpriseprojectmajortype_combox_store,
								emptyText : '请选择是否是第一承担单位',
								allowBlank : false,
								blankText : '请选择是否是第一承担单位'
							}, {
								xtype : 'textfield',
								fieldLabel : '项目名称',
								name : 'project_name',
								allowBlank : false,
								value : this.cfg.project_name,
								blankText : '项目名称不能为空',
								anchor : '99%'
							}, {
								xtype : 'datefield',
								fieldLabel : '启动时间',
								name : 'project_start_time',
								allowBlank : false,
								value : this.cfg.project_start_time,
								blankText : '启动时间不能为空',
								anchor : '99%'
							}, {
								xtype : 'datefield',
								fieldLabel : '结束时间',
								name : 'project_end_time',
								allowBlank : false,
								value : this.cfg.project_end_time,
								blankText : '结束时间不能为空',
								anchor : '99%'
							}, {
								xtype : 'textfield',
								fieldLabel : '政府拨付经费（万元）',
								name : 'project_government_money',
								allowBlank : false,
								value : this.cfg.project_government_money,
								regex : /^[0-9]+$/,
								blankText : '政府拨付经费不能为空',
								anchor : '99%'
							}]
						})
			}
		});
editenterprsie_project_formpanel_win = Ext.extend(Ext.Window, {
	cfg : null,
	panel : null,
	constructor : function(_cfg) {
		this.cfg = _cfg;
		this.panel = new editenterprsie_project_formpanel(this.cfg);
		editenterprsie_project_formpanel_win.superclass.constructor.call(this,
				{
					width : 500,
					title : '修改<font color="red">' + this.cfg.project_year
							+ '年' + getDataType(this.cfg.type) + '</font>项目数据',
					iconCls : 'configmanage',
					// layout : 'form',
					closeAction : 'hide',
					frame : true,
					modal : true,
					plain : true,
					items : this.panel,
					buttons : [{
								text : '保存修改草稿',
								scope : this,
								iconCls : 'itemadd',
								handler : this.submit
							}, {
								text : '取消',
								scope : this,
								iconCls : 'cancel',
								handler : function() {
									this.hide()
								}
							}]
				});
		this.addEvents('editok');
	},
	submit : function() {
		var form = this.panel.getForm();
		if (!form) {
			Ext.Msg.show({
						title : '提示',
						msg : '请正确填写数据',
						icon : Ext.Msg.ERROR,
						buttons : Ext.Msg.OK
					});
			return;
		} else {
			var pid = form.findField('pid').getValue();
			var eid = form.findField('eid').getValue();
			var project_type = form.findField('project_type').getValue();
			var project_is_major = form.findField('project_is_major')
					.getValue();
			var project_name = form.findField('project_name').getValue();
			var project_start_time = form.findField('project_start_time')
					.getValue();
			var project_end_time = form.findField('project_end_time')
					.getValue();
			var project_government_money = form
					.findField('project_government_money').getValue();
			Ext.Ajax.request({
				url : 'cxxqysjsb/enterprise_project/updateenterpriseprojectddata.action?',
				params : {
					pid : pid,
					eid : eid,
					project_type : project_type,
					project_is_major : project_is_major,
					project_name : project_name,
					project_start_time : project_start_time,
					project_end_time : project_end_time,
					project_government_money : project_government_money
				},
				scope : this,
				success : function(response, options) {
					if (response.responseText == 'ok') {
						this.fireEvent('editok');
						this.hide();
					} else if (response.responseText == 'fail') {
						Ext.Msg.show({
									title : '提示',
									msg : '数据传输失败',
									icon : Ext.Msg.WARNING,
									buttons : Ext.Msg.OK
								});
						return;
					}
				}
			});
		}
	}

});
Ext.extend(demo.module, {
			init : function() {
				this.datareportproject = new enterprsie_project_info_grid();
				this.main.add(this.datareportproject);
				this.main.doLayout();
			}
		});